Added writeToFile functions