Exporting the animation of an object to a text file with custom code
I am trying to do something similar, and the trick for me was to use this to advance the playhead...

bpy.context.scene.frame_set(i)


The below gave me the current frame over and over. Even though it did advance the animation in the viewport...

bpy.data.scenes["Scene"].frame_current = i