I would speak to her pediatrican to rule out any physical problems she may have. This has to be an embarrassment for her at school, we all know how cruel kids can be. If this only happened at school I would think she is nervous about asking permission to go and is waiting until she can no longer hold it. Try talking to her a little more and see if she comes up with any other reasons. But I wouldn't punish her, it may be making things worse. Good luck with this.
Actually I do think this is possible. She may not realize the urgency of needing to go in time to make it. Most kids of 9 do not WANT to go in their pants------- so I would work on that basis. If she does the littlest of motion that tells you she has to go, then tell her to take a break to go. If she is doing it at school, have her teacher ask her to go at intervals. good luck