Possible flakiness fix for test_dynamic_dependencies

test_dynamic_dependencies has been flaky lately, see #571. I can't reproduce it
locally, so I assume it has something to do with Travis running things more in
parallel than I do. test_dynamic_dependencies uses mktemp, which according to
the tempfile documentation should not be used and causes race conditions in
which another program may get access to the temp file first. Replacing this with
mkdtemp should fix the issue while also clarifying that a temporary directory is
wanted and not a temporary file. I haven't been able to verify that this will
fix the flakiness, but it should probably be done anyway. I also added cleanup.
Thanks, I wasn't familiar with that function. I guess we'll get another Travis trial as a bonus.