Ensured cache tests do not leak temp dirs

Refs #17215.