He didn't wait until the very end, but he did wait until the Union had just won a battle (can't remember which), and wanted to present it on a victory platform. He didn't write it earlier because he didn't want the border slave states that were on the verge of secession to feel that slavery was in danger. That's why he didn't want the war to be about slavery, but preserving the union.
Also, it may have had something to do with countries like Great Britain who were possibly going to ally themselves with the South. Lincoln recognized this, and saw that if he made the war about slavery, since the British had already made slavery illegal, England would not side with the confederates and fight for slavery.