Wild ducklings, like these baby Mallard ducks, are in fact typically only partly yellow:
Photo by TheBrockenInaGlory via Wikimedia Commons, used under the CC-By-SA 3.0 license.
While I'm no expert, I would guess that the mottled yellow-brown coloring of the juveniles is, at least partially, protective coloration, just like the somewhat similar pattern on the adult female's feathers. While it may appear conspicuous on open water, ducks in their natural habitat will often seek shelter among reeds and other vegetation, where the irregular pattern of light and shadow would create a very effective camouflage for the ducklings.
As for the all-yellow ducklings of domestic ducks, these presumably arose via elimination of the darker parts of the coloring as a result of selective breeding, perhaps as a side effect of artificial selection for the white adult plumage found in many domestic ducks today.
Specifically, according to a recent study of domestic duck genetics, it appears that the all-white plumage of domestic Pekin ducks is caused by a single recessive mutation to the MITF gene, which regulates melanin production. The mutation, when homozygous, causes the normal melanin production pathway in the skin to be almost entirely shut off, so that the adult plumage is pure white regardless of what other plumage color genes the bird may be carrying (a fact apparently known for a long time from cross-breeding experiments, even though the specific mutation behind this effect was not determined until recently).
Apparently, however, the yellow base pigmentation in young ducklings is not affected by the MITF mutation, and thus appears even in individuals homozygous for it. Presumably this is because the yellow color is produced via some other pathway, which is active in young ducks but gets shut off as they develop their adult plumage. The brown pigmentation pattern overlaid on top of it in wild-type ducklings, however, is controlled by MITF, and thus fails to appear in ducklings with two copies of the mutated version of the gene, leaving their juvenile plumage pure yellow.
As far as I can tell, the specific reason why the yellow pigmentation in ducklings is not controlled by the MITF gene still remains unknown. Or, if it is known, my Google search skills were not good enough to find it.