configure: improve temp file creation and cleanup