Ambergris is a weird and wonderful thing. It has been tremendously valuable throughout human history, but its creation and functionality have been shrouded in myth and superstition. To this day, no one has ever seen a whale actually excrete the stuff.

But we know for sure that ambergris comes from sperm whales, because it's been found in their stomachs as well as floating freely in the sea. And since the waxy blobs are always full of squid beaks, we think they're probably the whale's way of dealing with these uncomfortable hard parts. 

In general, squid go down pretty smoothly--after all, they're boneless invertebrates. Even the stiff pen that keeps their mantle straight is made out of protein that will eventually dissolve. But they have these calcified beaks that just won't go away, no matter how you pound at them with stomach acid. So--ambergris.

It's like pearls. Grains of sand irritate oyster innards, so they turn them into peals; squid beaks irritate sperm whale guts, so they turn them into ambergris. Or, it's sort of like an owl pellet.

Owls regurgitate their pellets, which may be one reason that a lot of people have believed that sperm whales vomit up their ambergris. However, due to certain similarities between ambergris and feces that I'd rather not enumerate, current thinking is that ambergris comes out the other end.

So, why is whale poop so valuable? It's been claimed to cure epilepsy and serve as an aphrodisiac, among many other outlandish ideas, but its modern-day value depends mostly on its smell and chemical qualities, which make it a good perfume ingredient. If you're into that kind of thing.

Anyway, I got onto this topic by reading an io9 article, which in turn references an older Sci Am piece, both of which agree that ambergris is produced exclusively by male sperm whales. 

Which made me go Whaaat? Both male and female sperm whales eat squid beaks, so I don't see any reason why they couldn't both make ambergris. I set out into the wilds of internet, and came across an 1823 printing of the Encyclopedia Britannica which lays it all out. Emphasis mine:
In an account communicated by Paul Dudley, Esq., in the 23rd volume of the Philosophical Transactions, the ambergris found in whales is . . . secreted and collected in a particular bag or bladder, which is furnished with an excretory duct or canal, the spout of which runs tapering into and through the length of the penis . . . and that therefore ambergris is never to be found in any female, but in the male only. But these circumstances are not only destitute of truth, but also contrary to the laws of the animal economy: For, in the first place, ambergris is frequently found in females as well as males . . . Secondly, No person who has the least knowledge in anatomy or physiology, will ever believe that organized bodies, such as the beaks of the sepia [=cuttlefish, related to squid, sometimes people confuse them], which are so constantly found in ambergris taken out of the whales, can have been absorbed from the intestines by the lacteals or lymphatics, and collected with the ambergris in the precluded bag above mentioned.
Take that, Paul Dudley, Esq.! You were destitute of truth, and clearly did not have even the least knowledge in anatomy or physiology. How could squid beaks migrate from the digestive tract into the penis? Weirdo.

However, if you don't wish to rest on the authority of the 1823 edition of the Encyclopedia Britannica, there is a much more recent reference illustrating the bisexual distribution of ambergris. In the 2007 thesis of Felipe Gómez-Villota, "Sperm whale diet in New Zealand," at the top of page 12, we read:
Ambergris was found in one of the samples recovered from a female sperm whale stranded near Napier.
So the next time someone tells you ambergris is only produced by male sperm whales, you can tell them that they are destitute of truth.

And thank a dead squid or two.