In my experience, the batch DRC hazard count has a long history of randomly incorrect values. In most cases, closing and re-opening the design fixes the problem. It seems to get tired after working a lot, and needs to take a break.
What we call a Mentorism.
As such, I suspect you'll be chasing your tail trying to fix the problem with your script. I think it's buried more deeply than any of us can uncover.