Use appdirs module to get appropriate cache directory.

This fixes an insecure temporary file creation bug on UNIX-like systems.