Thomas Harris, author of the Hannibal Lecter novels, said this: “I'm doing one of three things: I'm writing. I'm staring out the window. Or I'm writhing on the floor.”
Apparently, staring out the window can be very useful. A study at the University of British Columbia found that the parts of our brains associated with complex problem solving become active when we daydream.
So the point is that daydreaming might very well be a function of the brain that allows us to concentrate on matters that are more important, rather than focussing on the task at hand.
Daydreaming also count as part of the spontaneous path (as opposed to the deliberate path), thus the time in which we leave our brains to create new connections. The spontaneous path is normally active when we do tasks that require little attention or that is mostly automated, such as sharpening pencils and showering. Daydreaming, I would assume, comes in when a task is seen as unimportant or unchallenging, therefore our brains switch to concentrate on a more important subject, perhaps leading to an overflowing cup.