Fix file writing in test. Clean up system invocation