Write temporary files to ~/.cache

This also makes sure that the directory is protected the first time.