Simple answer: It cost companies money to do any, even doing nothing. The immediate issues with selling out of date food in most jurisdictions would be:
Do nothing (stockpile non-perishable.)
- Goods are assets of the company and affect internal and external accounting, especially accounting of value of publicly traded companies.
- Goods as assets are likely still assessed a value which the company will have to pay taxes, insurances and regulatory compliance.
Give away or sell at loss:
- Will likely reduce demand for future sales to some degree as noted in other answers.
- In case of perishables like food, could expose company to liability risk (I worked with some charities years back for the homeless and many food distributors simply couldn't donate surplus food because they are liable, in Texas, USA, for the quality and safety of all food that passes through their system to anyone for any reason.)
- Bad PR is also an issue, either when some one gets sick or simply that the managers misjudged demand so badly.
- Without a market to set prices for the goods, the fiduciary officers will find it hard to defend any price they set for the items either to stock holder or regulators. They could be personally sued for giving away assets of the company or face criminal action for stealing from the company's stockowners or taking action that manipulates the stock price.E.g. How would Sarbanes–Oxley in the US treat giving company assets away?
Back before detailed regulation and stockowner law suits on a hair trigger, officers of companies public and privately-held, large and small, had a little more flexibility in such matters but gradually they have lost almost all discretion. Most regulation today operates under the "everything not allowed is forbidden," model so if the regulators did not anticipate a need for an action, an officer takes the action at his/her personal risk.
Marketwise, there is an interesting analog in the petroleum industry. It's prohibitively expensive to store large amounts of oil, destroying it is economically impossible and today, way to costly in environmental regulations and only a few oil fields have the geology that allows oil to be returned to the ground.
The vast majority of the oil pumped out the ground will be sent through the whole system and end up as an end product 90-120 days at most after it leaves the ground. This lag time causes a significant market inefficiency in petroleum, because "Lifters" those who pump the oil out of the ground can only guess what the demand will be 'X' number of days outward. The oil will be sold period, at some price.
If collectively, the lifters pump to much, the price at the consumer end drop precipitately, but if they pump to little, a spike occurs. When oil prices suddenly plummet, you do see situations where companies are selling oil or oil products at a loss.
Regulation aggravates the problem, particularly the switch over in refining from seasonal versions of products like gasoline as well as regional difference e.g. California, in versions that make the products none fungible between jurisdictions.
The violent oscillations in petroleum prices caused by this lag is one of the reason that petroleum producers from the late-1800s up the present day have such powerful incentives to form cartels and/or have governments regulate the overall oil supply e.g. Texas Railroad commission, OPEC.
It's easy to see that any industry that operated under the conditions that whatever products they had in their channels would end up in consumer's hands eventually, regardless of supply, demand or finale cost, would end up as volatile as the oil industry.
For another example, one could argue that various "agricultural supports" of most nations are primarily devoted to preventing just such volatility. Farmers face the same problem, they plant in spring, harvest in fall, and then sell their crop for whatever the price might be. Perversely, the better the growing season, the more productive the farmers as a whole, the more likely they are to go broke.
In developed nations at least, vastly more amounts of food are destroyed or more often, farmers are paid to never grow it, than get wasted in the distribution system. Most governments believe it's better that food prices remain somewhat higher overall, within certain ranges, than food prices oscillate to much.