write to files in proper format