Fix descriptor leaks in writeFile and appendFile
Remove redundant code per review
Merge pull request #257 from humphd/fix-ofd-leaks

Fix descriptor leaks in writeFile and appendFile