Fixed bug where outfile was not properly removed