Fixes#1710
What do you think?
* It first uses `TEMP_DIR` (`/debug_ramdisk`) if it exists + is is
empty.
* Otherwise it tries to create a random directory in `/dev`.
* If that fails, it goes through a list of directories (including
`TEMP_DIR_LEGACY`), and chooses the first one that is empty.
* If no empty directory it chooses the first one that exists
---------
Co-authored-by: user <user@localhost>