Re-added writeFile function