Performing Hajj is obligatory on every muslim, while donating money to poor people is voluntary and a mere act of charity. There is a rule in Shari`ah that states that if the observation of an obligatory act contradicts a supererogatory one, the former takes precedence over the latter. Accordingly, since Hajj is mandatory upon a person who is able to perform it, one should perform Hajj first because it is obligatory, and they can afford it.
Moreover, there is a hadith that warns against deferring Hajj particularly if one is able to perform it. The majority of jurists maintain that Hajj must be performed as soon as one is able to, and delaying it is counted as a sin.
However, one may do this in case of voluntary Hajj, i.e., if we already performed Hajj once and we want to perform it again. In this case, we would say it is better to donate the money to poor Muslims who are in a bad need of money.