diff --git a/fsl/utils/tempdir.py b/fsl/utils/tempdir.py
index f17aa4482ef2db629e0f363c4fc70679ad57866c..c5931454cbeb5f14bfa2a2dabeb7dd690d9f593b 100644
--- a/fsl/utils/tempdir.py
+++ b/fsl/utils/tempdir.py
@@ -21,12 +21,16 @@ import contextlib
 
 
 @contextlib.contextmanager
-def tempdir():
+def tempdir(root=None):
     """Returns a context manager which creates and returns a temporary
     directory, and then deletes it on exit.
+
+    :arg root: If provided, specifies a directroy in which to create the
+               new temporary directory. Otherwise the system default is used
+               (see the ``tempfile.mkdtemp`` documentation).
     """
 
-    testdir = tempfile.mkdtemp()
+    testdir = tempfile.mkdtemp(dir=root)
     prevdir = os.getcwd()
     try: