I hate getting too personal on here but totally used to do it too ( I did it in a different way than my son and I hid it better than he but it was essentially the same thing).  So I think it may have a genetic component.  My father used to pace constantly and be in his own world while pacing around repetitively.  I remember doing it as far back as I can remember, but it only got "bad" when I was anxious and stressed.  In my teen years, I had so much trauma and crazy bad home stuff happening I couldn't do anything but "maladapaptive daydreaming."    It was actually very debilitating.  But I got out of the situation eventually (over 4 years) and recovered.... Obviously I am fine now and don't do it at all now. So I guess one can also grow out of it to a certain extent?