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.

Why ducklings are yellow?
The chapter by Douglas Futuyma in 'Evolution' (Losos et al 2013, Princeton) states that natural selection can occur at the species level. Futuyma states that if natural selection occurs at the species level it does not occur at the individual level: 


  Neither gene selection nor species selection has molded the advantageous characteristics of individual organisms; rather, they have affected properties at the gene level or at the species level. 


But how does natural selection occuring at the species level not affect individuals? Surely any selective advantage of a particular species must occur among particular individuals of that species. For example, if Species A is selected because it is browner than Species B, this will be because individuals of Species A are browner than individuals of Species B. 
