added writeFile method