Updating of writeToFile

writeToFile will rewrite the whole file based on the tempStorage.