To need something for something else
- We need this money for the kid's baseball team. [“to the team” does not work]
- That isn't needed for making a fortune. [to make also works, AND “making a fortune” is a noun-gerund phrase]
- I need this money for him. [“to him” does not work]
She needs the rice for the sweets. [“to the sweets” does not work]
Notice that in the preceding cases, there is a noun (pronoun) or gerund noun after the preposition for. There is no verb [making a fortune is a participial phrase functioning as a noun, Making a fortune is not easy.]
To need sth for is not grammatically the same as:
To need something to do something
However, HERE they can mean for the purpose of in those examples.
But they do not exhibit the same grammar. And for and to are not always interchangeable as can be seen in the examples at the beginning of this answer.
This is not a grammar rule. These are the grammatical features of the two sentences.