Fix descriptor leaks in writeFile and appendFile

Always release the fd, no matter if we error or succeed.
Redundant. Will be cleaned up when it goes out of scope.