The current working theory is that Giuliani and his buddies at the FBI and NYPD were going to leak it – recall that he was on Fox cackling to himself and saying they had a surprise coming.
So Comey sent the letter in an attempt to maintain some control over the situation instead of letting people be lead to the wrong conclusion. In less contentious elections he might have had more success.
Something vaguely similar happened in 2012, when an FBI agent contacted Eric Cantor in late October and claimed that the Department of Justice was covering up a scandal to protect Obama.
That particular scandal was the affair between David Petraeus and Paula Broadwell, and while the investigation had already been completed, it was kept hidden – even from Obama – until after the election.
It was somewhat different this time round since the candidates were involved directly, but it still shouldn’t have been disclosed. In Trump’s case it wasn’t. Jason Chaffetz had other ideas when it came to Hillary.
There appear to be tons of other facets to this whole thing, and I personally believe Comey’s letter will eventually be seen as a fairly inconsequential twist in the story.
Hopefully everyone lives long enough to see it all come to light.