Fix tmpfile race

Use a tempfile to write the open file in editor part with a better umask to avoid a potential timing attack with the /tmp/completeme.sh fixed name.