Because the water's surface is not flat. The water has surface tension, which tends to pull the water up along the edge of the glass. In other words, the water around the edge is higher than the water in the center. The cork seeks (via the buoyancy force) the highest position, which is at the edge.
You can make the cork float on the center, though, if you're clever.
Fill a glass (with cork in it) to the brim with water. Slowly add water so the water goes slightly over the brim but does not spill. You'll find the cork now floats in the middle of the glass!
I just tried this with a cork - It works well.
Perhaps we should have a forum (or reference links?) of interesting experiments, along with an explanation of how they work. Between us all we must know hundreds of great, but simple, experiments. I suppose that this would be hard to arrange though.....