Unsold food that is given away creates a liability if it causes problems. Food banks are the middle man in that respect, where they can toss things that aren't going to stay good and provide for people with the rest. So here's where government, regulation, and socialism comes into play. Companies should be encouraged with money to do something other than toss that food. Better systems should be in place to move that food to the food bank. Better regulation there to make sure that the food is being examined well enough. More places for all this to happen.
This ignores fixing the real problem, profit driven consumption, societies where people aren't able to provide for themselves, etc.
So by itself you aren't going to get unsold food to the needy, the risk and cost is too great for companies.