The camera can't know what white balance to use, it can only make a guess based on the image data (or sometimes an external sensor, as Itai mentioned in his answer).
If I for example take an image of a blue wall, the camera thinks that I have taken an image of a gray wall in blue light, and the image ends up gray instead of blue. (This is pretty much the same phenomenon as when I photograph a white or black wall with automatic exposure, and the camera sets the exposure so that both end up gray.)
I always use automatic white balance, and adjust it manually when devloping from the raw image. My experience is that sometimes the automatic white balance is spot on, most of the time it's very close, and in some rare sitations it's way off.
Note also that the "correct" white balance setting isn't always the exact color temperature of the light source. Sometimes an image needs a slight color change to look natural, and some may even need quite a lot. An image taken in bright sunlight may need to be slightly more yellow, and an image taken in the blue hours may need a lot of blue.