There are two answers to this question, depending on how you interpret the 5th season finale.
If you assume that Chuck Shurley is exactly what Castiel says he is, than the most likely explanation is that Dean was going outside the "plan" in trying to stop Sam's confrontation. We know that the "plan" from both Hell and Heaven is to release Lucifer and ultimately bring about the Apocalypse, while Dean is trying to stop it. There are a number of hints dropped during those two seasons that Sam and Dean (likely due to their unique nature and the intervention of other angels) are managing to do things to disrupt that plan that the angels couldn't foresee. Depending on the precise source of Chuck's visions, it's possible that he can only foresee how things are supposed to happen, and when Dean goes off-script he cannot see that.
It's also possible that Chuck's visions are simply not always complete. There's no reason to believe that Chuck knows everything about the future, merely that he knows a lot. Otherwise he wouldn't have, for example, gone to the Supernatural convention at an actually-haunted house.
The alternative explanation, which follows most people's interpretation of the 5th season finale, is that
Chuck is actually God Himself, escaped to Earth to avoid the bickering in Heaven
in which case it's true that he "never wrote it" but clearly knew exactly what was going to happen all along.