Hi Santhosh,
Maybe that is happening because you're removing elements from an object (collection_wrapper) inside your loop.
Can you try to create an collection wrapper copy by using GET_COPY method, and then use and loop the iterator on your copied object, and remove the unwanted entities on your main object?
Kind regards,
Garcia