You should have only one call to write_particle_track inside this do loop or else the same position will get written twice. You will also need to have one call either before the do loop or after it.