Imagine yourself in his position. Just imagine how you feel when you are in the total dark in a strange place. Don't you just wish that you could turn the lights on just to see where you are and what is around you? At first, he is, just like we would be, scared. It is pitch black, he doesn't know where he is, and because of the "thousand vague rumors of the horrors of Toledo" that he has heard in the past, he fears coming tortures. Of those rumors, being buried in a tomb alive terrifies him, and that thought "suddenly drove the blood in torrents upon my heart" and he begins to explore, trying to determine if he is, in fact, in a tomb. But, he doesn't have the convenience of a light switch to throw on. So, to gather some information about where he is, he uses what has been provided to him. He "cautiously steps" about, with "arms outstretched" to try to feel his way around and get his bearings. As he wanders about though, he realizes that he could be walking in circles, and he is not gaining any useful information about the dimensions of his prison. So, he
"tore a part of the hem from the robe and placed the fragment at full length, and at right angles to the wall"
so that if he feels it again, then he'll know he has come full circle. As he walks, holding on to the wall, he counts his steps, and is able to estimate that his prison is "fifty yards in circuit" but still has no idea of its shape because there were lots of angles. He decides to walk across the prison but trips, with the tip of his head landing on the pit; that is how he discovers its presence. So, through walking, counting, and using his robe, he is able to explore, and at least feel a little bit in control of his circumstances. To know that little bit, even if not very useful, is very important in such a stressful situation.