Fix file writing bugs in test_utilities.py