extra::tempfile: replace mkdtemp with an RAII wrapper (Closes #9763)

this incidentally stops `make check` from leaving directories in `/tmp` (Closes #9764)