The pyramids aren't surpassed in hammer cost for couple of eras, by which time you have forges and large populations to work. Plus they come at the crucial early stage of development. I can't think of a more expensive wonder, relative to the capabilities and the alternative needs of a civ at the time in which they are built.
The handful of wonders that beat them on certain maps is maybe a mutilated handful, but I agree the Pyramids aren't always best. Just usually.
Wonders that pursuing mids might cost that are potentially superior:
1. Great lighthouse: with enough foreign trade (or overseas). Gold star on this wonder if you can get considerable "intercontinental" routes with sailing. Every city will match the raw yield of a rep spec at pop 1 w/o working a tile just from this wonder. It is, however, powerful enough to compete/beat mids for certain leaders under normal conditions. Assuming you have enough coastal cities to merit it at all.
2. Great wall: with non-standard settings like very large maps or raging barbs, this thing saves you more hammers than practically any other option. With the occasional long-range spawn it can be competitive even on standard maps, and you better hope your 1st unit doesn't get hit by a bear so you can realize it.
3. Oracle: on higher levels it can go pretty early. However, it's cheap and unlike mids it doesn't rely on (nor is it typically practical to use) a resource to construct it in a reasonable time. Some oracle gambits are ok, while others can be very powerful. Well-placed religion on a continent that would never have any otherwise can completely change the diplo game, while metal casting for IND, monarchy, or even mathematics all have merit too. Cheesecraft like oracle ----> theology can also help seal a game, so this one is definitely worth a look.
4. Great library: with marble, > mids IMO. Rolo correctly points out that BTS nerfed it a bit, but it is still the gold standard of GPP wonders and if you have any hope of using its path for trade, it is a potent wonder to the point of beating mids w/o stone. This one is less dependent on *not* pursuing mids at least.
5. Colossus: I'm serious. You have to have a map that favors it though.
6. Temple of Artemis: rarely does this beat pyramids, but it's worth 5 GPP and it's boosted by marble. If you're going to run a wonderspam GPP farm, it's a very sound choice.
Of course, with stone and some starts mids can easily trounce any of them. Some starts they'll ALL be a bad play. It's hard to pick a *best* wonder if you exclude the only one that is broken beyond belief because unlike a lot of game elements wonders and their application is decently balanced...well outside of the AP.