How can I get the location of all the objects in the scene at a desired keyframe using script?
the obj.location results in the local location, not including parenting relationships. Same goes for the rotation_euler. 
loc = OBJ.matrix_world.translation
rot = OBJ.matrix_world.to_euler()
text_file.write('COORDINATES:', str(loc.x), ',', str(loc.y),',', str(loc.z) + '\n')

the matrix_world returns the actual world coordinates of the object after calculating all parenting and constraints.