Space isn't really cold, not at least when you're close to a star like the Sun. After all, the Earth's isn't cold (well, relatively speaking), despite the fact that it sits in space. Sure, there's some internal heating from our molten core and some greenhouse effect from our atmosphere, but the underlying reason that the Earth is warm (again, relatively speaking) is because it's in thermal equilibrium with sunlight at a distance of 150 million kilometres from the Sun.
So if you stick something in space at L2, it's essentially at the same distance from the Sun as the Earth and thus, roughly speaking, it'll end up at the same temperature as the Earth.
The big difference, however, is that there's no atmosphere to transport heat by conduction or convection, so the side of the object that's facing the Sun will get hot and the other side, in the shade, will be colder. Of course, conduction by the object itself can transport heat from the hot side to the cold side, evening things out a bit. But if you can thermally isolate one side from the other, the side facing away from the Sun can get really, really cold, as it radiates any excess heat into the 3K "heat sink" of the Universe.
Which is exactly what spacecraft at L2 do. They have a hot side, facing the Sun and Earth, generating power to run the satellite and to communicate data back to Earth. Then they have a cold side, separated from the hot side by a sunshield and facing out into space, which can then get very, very cold, provided the two sides are thermally decoupled. You stick your telescope and instruments on that side and you can get nice and chilly.
(That said, you can only reach about 30–50K or so, which is fine for near-infrared observatories and their instruments, but the instruments used by far-infrared and sub-millimetre observatories need to be much colder, down around absolute zero, in order that their detectors don't blind themselves. That's why Herschel has liquid helium and why it will go blind when it runs out. Being at L2 is only half the story for Herschel.)
The beauty of L2 is that you keep the Sun, the Earth, and the Moon shining permanently on one side of the spacecraft, but never on the other side, if designed well. Spacecraft like Hubble in low-Earth orbit have to contend with half the sky being permanently filled with a big hot object called the Earth, and as you go around in orbit, the combined Earth and Sun illumination is constantly changing: not a good place to get a spacecraft really cold.