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

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