Move fclose and unlink to before the return so they're actually called.
Removed pointless try and catch. None of the functions threw an exception and it was just rethrowing. Also Exception didn't exist in that namespace