Prevent filehandle from leaking

The filehandle `t` is not properly closed in the event of an error condition and leaks.