It sounds like you are still in autofocus mode and have your camera set to autofocus with a press of the shutter. Therefore, every time the intervalometer triggers the shutter, it is trying to autofocus and can't. When you are shooting astrophotography, autofocus is not that helpful. There are two possible fixes for keeping the focus:
1) Set autofocus to the back button focus (its next to the "i" button on a D5100. Back button focus has many advantages and by separating the autofocus from the shutter button, you never have to worry about an intervalometer (or other remote trigger) causing a refocus. Do an internet search for "back button focus" to learn more about that. In my opinion, this makes things much easier once you get used to it.
2) Easy way. Get your focus perfected however you do that, then simply switch the lens,or the camera, to manual focus (but it is typically easier to use the switch on the lens, especially with a D5100 as you need to go into the menu to do so on camera). That will essentially lock the focus as you set it. Alternatively, do your focusing in manual and leave it there. Be careful not to bump the focus adjustment on the lens before setting the intervalometer and it will keep the focus exactly as you set it.
Finally, you want to make sure the camera is set in "Shutter Priority" rather then "Focus Priority." Focus priority prevents the shutter from being release if the camera thinks its not in focus. This can be helpful sometimes, but I tend to leave it in shutter priority which means that even if the camera thinks its out of focus, it will still take the picture. I find that if you are trying to do anything creative, focus priority can be a pain. Also, if you are shooting fast action, like sports, it can be really frustrating.
There are other issues with using an intervalometer with long exposures. First, turn off in camera noise reduction. This causes a delay between shots of approximately the same length as the exposure. Fine for quick shots, disaster for a sequence of 20-30sec shots. Second, make sure there is a sufficient delay set on the intervalometer between shots (with in camera noise reduction turned off you will only need a few seconds). If it tries to trigger the shutter too quickly, it will just skip an exposure.
Final note, the D5100 has a built in intervalometer. All the above still apply when using that though.