This approach should make the creation of the file more atomic, to fix a bug reported by Dinh. This patch has one change from Zack's original version: it avoids $<, since Dave Hart tells me he thinks that's not so portable. (commit message by nickm)