Changed function to write to file instead of firebase