change code to write file

change code to write file