diff --git a/worker/uniter/uniter_test.go b/worker/uniter/uniter_test.go
index <HASH>..<HASH> 100644
--- a/worker/uniter/uniter_test.go
+++ b/worker/uniter/uniter_test.go
@@ -848,7 +848,8 @@ func (s *UniterSuite) TestRunCommand(c *gc.C) {
 		return filepath.Join(testDir, name)
 	}
 	echoUnitNameToFile := func(name string) string {
-		return fmt.Sprintf("echo juju run ${JUJU_UNIT_NAME} > %s", filepath.Join(testDir, name))
+		path := filepath.Join(testDir, name)
+		return fmt.Sprintf("echo juju run ${JUJU_UNIT_NAME} > %s.tmp; mv %s.tmp %s", path, path, path)
 	}
 	tests := []uniterTest{
 		ut(
don't move test file to checked path until written