redefine writeFile and appendFile using withFile