Extract object properties from animation for each frame
I haven't tested your code, but if everything else works, you will be fine after replacing
location = obj.location

with
location = obj.location @ obj.matrix_world