Basically it allows 재료 to take the object marker. 필요하다 – even though it's typically translated as "to need" – is in fact an adjective; a more narrow translation would be "to be needed, to be necessary". Therefore, the thing that is needed takes the subject particle: 재료가 필요해, not 재료를. But if you add -로, the verb is technically just 하다, not 필요하다 (maybe something along the lines of "to take as a necessity"), so 재료 can take -를.
Think of this sentence literally. 하다 is being used as the verb. The object that the person is going to do something 'with' (로) is the needed ingredients.
로 is like "by means of" or "via" or "using" it is the means through which the action is taken in the sentance is my understanding. "Korean로 speak to me." Means talk to me in/using korean. Thats how i think of it
I think the 로 here emphasizes the 필요 by saying 'in a necessary manner or by way of necessity'