Add function to write file