Fix a few cases where temporary files were being left behind.

A few code paths did not properly cleanup after themselves and that has
now been fixed.