Update the TOC *before* the file is written, not after

otherwise, Vim behaves strange