add method writeFile()