Moldy wine almost always occurs from poor production practices or improper sanitation, and rarely after bottling. The first step in correcting a moldy wine is diagnosis -- you can sometimes save a wine if you identify the type of mold and treat it accordingly. In addition to sanitizing all winemaking equipment, you must avoid contaminating unbottled wine with dust and debris, which promote the growth bacteria and mold spores.
If your wine grows mold while fermenting, it means that it has been contaminated with mold spores during the wine-making process. Wine fermentation needs to take place in a sterile environment so that microbes like mold and bacteria cannot infect the wine and ruin it. Fermentation is the result of yeast converting sugars into alcohol, but do not assume that the wine can sterilize itself just because it is producing alcohol.
The solution to a mold problem in your wine is proper sanitization of your wine-making equipment. You must sanitize everything that comes into contact with the wine with a metabisulfite sterilizing solution, including primary and secondary fermenters, siphon hoses, bottles, air locks and all utensils. You should also add sodium metabisulfite tablets, commonly known as Campden tablets, to your wine before you rack it to discourage microbial growth.
In addition to following strict sanitation procedures, make sure that you are using the proper equipment when making your wine. Do not try to make wine by simply letting it sit in an open container -- you must isolate the wine in a proper fermentation vessel to keep it from being contaminated by microbes. Some home wine-makers use their own methods, such as putting a balloon over the top of the fermentation vessel. The correct method is to use an airlock filled with sulphite solution, which lets air escape without outside air getting in.
Flowers of Wine
What looks like mold may actually be something called flowers of wine. Flowers of wine is a spoilage yeast growth that forms white, powdery blooms or a film over the surface of wine that has been contaminated. It needs oxygen, so keeping your wine properly sealed with an airlock during fermentation should prevent the problem from occurring.