fixed error in write to file