Fix the file clean up routine

This fixes the file clean up routine, as there are some cases where
calling destroy on a writable stream will close the file immediately
and the following code will not delete the file since it now looks
like the file was never opened.