Where did it come from? According to Wikipedia:
Around the fifth century, the European Celts believed that animals had certain supernatural powers on special days that were halfway between the winter solstice and spring equinox. Folklore from Germany and France indicated that when marmots and bears came out of their winter dens too early, they were frightened by their shadow and retreated back inside for four to six weeks. This was adopted by the Romans as Hedgehog Day.
When Christianity came into being, the formerly pagan observance also came to be called Candlemas.
In western countries in the Northern Hemisphere, the official first day of spring is about six weeks after Groundhog Day, on March 20 or 21. About 1,000 years ago, before the adoption of the Gregorian calendar when the date of the equinox drifted in the Julian calendar, the spring equinox fell on March 16 instead. This was exactly six weeks after February 2. Assuming that the equinox marked the first day of spring in certain medieval cultures, as it does now in western countries, Groundhog Day occurred exactly six weeks before spring. Therefore, if the groundhog saw his shadow on Groundhog Day there would be six more weeks of winter. If he didn’t, there would be 42 more days of winter. In other words, the Groundhog Day tradition may have begun as a bit of folk humor. (Photo courtesy of J. Day)