Make tests more robust and use a tmpdir instead of selectively removing files.