CXX-243 Refactor batching loop in writers

The existing loop, while correct, introduced a lot of state variables and iterator
manipulation. Some compilers were unable to prove initialization of all state
variables on all paths.

Refactoring to use a double loop and two tracking iterators removes the need
for the extra state and iterator manipulation and elminiates the warnings.