re-write method writeToFile()