Well, there's a few things to consider, and I had to do a little review myself to straighten out some things, so
wikipedia is a good place to start.
First, temperature is a property of mass and therefor, pure vacuum has no temperature because there is no mass. That being said, there is pretty much always some mass in a reasonably sized volume of space and the vacuum is not perfect.
Next, keep in mind that thermal energy or
heat can be transferred through
conduction,
convection, or
radiation.
For your scenario of space, I think convection will be negligible since it deals primarily with a flowing medium such as water or air. Similarly, conduction refers to heat transferred through direct contact of masses (like in metals). This would occur in space any time a particle or molecule of gas collides with your test object. Energy is transferred during the collision just like in NASCAR. Again, since this effect reduces to zero in a perfect vacuum, I'm guessing this is negligible in space, so we are left primarily with radiation.
So, to oversimplify thermal radiation, lets just say that your object in space is constantly releasing thermal radiation and simultaneously absorbing energy from the sun, the earth, and any other objects nearby with a measurable mass and energy. The amount of energy released and absorbed by your test object will depend greatly on the molecular characteristics of the object itself since it will be likely to absorb some wavelengths of radiation more than others, which may or may not correspond well to the wavelengths of energy being released by the nearby radiating objects. At equilibrium, the object will balance the energy it is releasing and absorbing and come to a rest temperature dependent on all the above mentioned variables.
One
example wikipedia had was interesting. Ballpark figures of course: a typical person will radiate about 1000W of energy, but in a typical room-temperature room, will receive back about 900W from the room resulting in a net loss of 100W due to radiation.
More closely related to your example, under "temperature in a vacuum" from my first link, if you consider your thermometer to be a perfect
"black body", meaning it absorbs all wavelengths of light (none is reflected or passes through it), and place it in orbit around the earth then it should equilibrate to about 281 K (+8 °C), which is about the same as the average temperature of the earth. If the thermometer were to stay in the shade of the earth, then it would end up closer to 236 K (-37 °C), due primarily to radiation from the earth. And finally, as you mentioned, if you move this black body thermometer into deep space, then it would essentially equilibrate with the cosmic background radiation at about 2.725 K.