fixed write file issue.
now it works!