added writeFile function to output text