The chemical reactions and pathways resulting in the formation of a mycotoxin, any poisonous substance produced by a fungus.