Is that what the script you shared is doing? To me it seems it would delete closed topics that were created x days ago. So a topic which is closed quite a while after it was created because there were new replies in a longer timespan might get deleted almost immediately.