Close the file only after deleting

According to man flock; closing a file releases the lock held on it.
That means the currect code leaves a window where another thread or
process can access and lock the file before it is deleted, making
document reserving non-atomic.

Fix this by deleting the file before closing it.
This also obviates the multiple File.exist? workaround.