Cleaning film out of plastic drain pipe
That sludge is really just a mix of soap, water, skin cells, hair, tooth paste and all the other lovely stuff that goes down your drain. I doubt it is fungus.

You can't really prevent it.  There are all sorts of chemical and non-chemical mixtures you can try to clean it out, but I think removing the trap and cleaning it out is the best bet. If the trap is easy to remove, why pour harmful chemicals down and into your water supply?

If the sludge is soft and comes off easily, you might have some luck filling the sink with really hot water and then draining it quickly.