Hi Sanket-
I am not a scripting guru, but given that the command reference manual lists "$L children" for showing just the immediate hierarchy and "$L cells" for showing all the cells, I suspect that when the design has a depth of more than 2 you are getting the lower-level cells repeatedly. This would cause a lot of unnecessary work.
Speaking of which, why the complete flattening? If you would like to see the layout without hierarchy, why not just run calibre -drc without -hier, and write out the results using COPY and DRC CHECK MAP?
Also, I checked with a co-worker who knows the DRC side better than I do. He tells me "There is no such thing as an unused cell reference. Unused cells, yes; references, no." I'm guessing you do mean cells here, but if you truly are just concerned with references that don't have attached cells, you don't need to be.
Hope that helps-
Sam.