What's this part from inside the steering tube? I wanted to replace a stem with a new one, so I first tried to screw the top cap off. What happened is that instead of the cap, the piece in the picture came out. What is the name? Is it bad that it came out?

 

I managed to take the top cap out of it. Is it enough that I screw that piece back on the star nut?
What you have looks like upper part of an expander bolt. If the lower part is still in place, you can just screw it back. If not, you may have to fish the rest of the parts from the steerer tube and put it together before installing.