Notice how the democrat always has a huge lead until right before the election and then the polls tighten. They do this for 2 reasons.
1) The early polls are used to sway public opinion. Most people are influenced by the group mindset. Read Robert Cialdini books like The Psychology of Influence or Pre-suasion.
2) They have to tighten the polls before the election to remain credible. If they are way off no one will trust them for the next election.
The media is nothing more than the advertising wing of the Democratic party.
I believe there's actually a 3rd reason:
The "Oh shit, they actually believed us and thought it was in the bag" reason.
More people do absentee, or early voting these days. Once they start seeing it's not only way closer than they were telling viewers, but that Dems might lose; they have to scare people to get them out of the house to vote. It gets people who might not have voted riled up to go do so, and creates a "story" for them to cover. Win-win......unfortunately, it got them a loss this time.