Don't append for first iteration

The first iteration of the appending function should be a write operation to overwrite the previous output file.
we should move the index check to the front. its a microopt, but since it is the lowest cost thing to check, might as well do it first :]