fix writeToFile bug