robust output temp file output and cleanup

preparation for pass handling