Use a thunk to cause outfile to be closed