fixed writeFile, please check