Use tempdir() to create temporary directories for testing

This is the first step towards being able to run tests i parallel.