Finish writeFile method