The distribution food chain in the UK (and I assume the EU) requires all refrigerated food to be between 0C and -5C (iirc - this was a while back) for the entire journey. At least once a week a truck would turn up with a fridge problem that caused the temperature to go above 0 for over 5 mins. We would dump the entire lot. The food was perfectly good, it was still frozen, perfectly edible, and the warehouse guys regularly snatched their lunch from it. But unsuitable for public consumption.
Orders were often mis-placed or fat-fingered, and too much food would get delivered (or too little, but that's another story). Sometimes the stores would accept an over-delivery and allow it through, most times not, so it got destroyed.
Food deliveries to our centre had a specific 15-minute window. If the vehicle arrived outside that window, we would try and accomodate it if we could, but often couldn't. In extreme cases the truck would not be unloaded and have to return to the producer. Sometimes they took the food back with them. Sometimes they dumped it at our place and went back empty, because it would go out of date before it could be re-delivered.
The saddest case I saw: a supermarket chain buyer found an artisan cheese producer in Wales who was making amazing cheese. The buyer set up the contract, the artisan bought a van to deliver the cheese to us. But no-one told them the specs. They turned up in a nice little refrigerated van, when all our docks only accepted articulated trucks. We couldn't handball the produce without exposing it to ambient temperatures, so we couldn't accept delivery. Poor sod had to drive back to Wales with a van full of unsold cheese that was going out of sell-by date and was packaged in packaging. I expect most of that was destroyed.
This was one interaction in an entire distribution chain. Every interaction was this leaky. And that didn't count the final stores who (as everyone knows) routinely destroy perfectly edible food that has reached its sell-by date.
There have been initiatives to get this edible food to people in need. All of them run into the legal problem that you cannot serve people food that has passed its sell-by date. It's perfectly edible, but if someone gets food poisoning after eating it then that's on you, and there's no way of dodging that liability. People in poverty have a right not to be poisoned.
The "ugly food" thing is a product of EU legislation (in the UK anyway). I was amazed when I moved to Australia at how ugly the veggies are ;) I'm pretty sure that the ugly food gets sold at a lower price to food manufacturers (as you say).