Blender background simulation (GUI-less) is different from the actual simulation
Found the method that selects all the objects. I added the below line before visual_transform_apply() and it works as expected. 

bpy.ops.object.select_all(action='SELECT')