Although it has been derided in the past as infantile, neurotic or failing to be mentally disciplined, neurologists have discovered that daydreaming - and more specifically, wandering mind - is vital for certain brain functions. They've found that a wandering mind can be protective and even help you stay on course for longer term goals.
A wandering mind helps the brain unfocus from repetitive, menial tasks. For example, driving down an empty highway, or jobs where the only requirement is to push a button at a certain time. There's also an 'incubation effect,' that happens when the mind wanders. If you're doing your homework and you can't think of how to answer a question; your get distracted and your mind wanders, your brain still processes the information and may come up with the answer later.
It's not all good, of course. If your mind wanders while you're reading a book, you'll probably not get any information from it. If you let yourself daydream too much on a highway, you'll get into an accident. However, their studies found that for creative tasks, people need their mind to wander; however, they also need to have enough awareness to catch the creative ideas before they leave the mind.