It's true that a major reason for the popularity of foundations is legal tax avoidance: you can donate to a foundation in a year when you have lots of income, get the tax benefit in that year, and not have to make a charitable donation in the same year. The foundations is allowed to sit on most of the money for a long time. However, crucially, when the money leaves the foundation it must go to an approved charity. There have been some high-profile abuses of foundations, but that's simply illegal, the same way it would be illegal to not make a donation in the first place and claim a tax exemption.