tests: only write cache file if it changed

Tests sometimes fila when running multiple parallel tests using the
same cache file because it is written everytime a test parameter
is read. Since there is no locking, this might fail from time to time.