Python variable is not persistent/ changes from unrelated bpy.ops line
obj.rotation_euler is a reference to the rotation object which is affected by bpy.ops.object.transform_apply. In order to store the old rotation in a variable you can use:

rot = obj.rotation_euler.copy()