@simontatham look I'm following and bookmarking you so 👍
I have also figured out how to make bash do this without Emacs. Ok it's real.
I'm just saying the idea of somebody running code and editing it at the same time (despite your use case) is for the most part a fiction, it requires
1. Editing configuration away from defaults, or
2. Overwriting the file from within the script whilst it's running
Edit: some possible setting, maybe
http://www.gnu.org/s/emacs/manual/html_node/emacs/Backup-Copying.html