diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm
index 0193d57..4f4058b 100644
--- a/src/test/perl/TestLib.pm
+++ b/src/test/perl/TestLib.pm
@@ -37,8 +37,9 @@ use Test::More;
 
 # Open log file. For each test, the log file name uses the name of the
 # file launching this module, without the .pl suffix.
-my $log_path = 'tmp_check/log';
-mkdir 'tmp_check';
+my $log_base_path = $ENV{TESTDIR} || cwd();
+my $log_path = "$log_base_path/log";
+mkdir $log_base_path;
 mkdir $log_path;
 my $test_logfile = basename($0);
 $test_logfile =~ s/\.[^.]+$//;
