We always should be writing an LF after each ID.  Also, the IDs know how to copy themselves out better:

  id.copyTo(fos);
  id.write('\n');

Because of these tiny writes, the FileOutputStream should be a BufferedOutputStream so we can write everything in a single system call, rather than two syscalls per object being merged.