fixed write to file