He wasn’t just palling around with Epstein, his friendship continued after Epstein was convicted. His excuse was that Epstein gave him access… as if Bill G wasn’t the richest person on the planet at the time.
When I hear the name "Carnegie", I think of music and libraries, but his contemporaries would think of emotional abuse and robber-barony.
There are certainly many charities that are ineffective at their mission, inefficient with their funds or working on a mission that few would consider worthwhile. (And there are also some great charities out there that are effective, efficient and important, such as https://givedirectly.org.)
But charities (of which non-profit foundations are a subclass) aren't a "tax dodge". Money that you give to a charity is untaxed, so you can claim a refund on income taxes you've already paid on that money. But you don't get new money that you haven't already earned from the IRS; every penny given is money that you already had, and the tax refund is purely of tax that is no longer due on that money.
It's possible to be cynical of the motives of some philanthropic gifts, but Gates (and others) aren't financially better off from their giving itself.