AFAIKAs far as I know, there was no Jackson commentary on that specific scene, so one can only speculate.
As for "Why""why", the most cogent speculation I have seen on the forums is that the scene served to:
Highlight the Witch-King'sking's power
Therefore make Merry's and Eowyn'sÉowyn's takedown of him all the more heroic.
A second theory was that this was to highlight the power and contribution of the World of Men - Gandalf is almost beaten and can be killed by such a powerful adversary, yet saved by the fact that WKWitch-king needs to go away and deal with Rohirrim - which, if you know the backstory of Istari, actually jibes with Tolkien's overall vision of the order of things (Olorin'sOlórin's mission is to inspire Middle Earthers-earthers to fight Sauron, not to fight him himself with his MayarMaiar powers).
This has further symbolic significance in that this mirrors Gandalf the White's breaking of Saruman's staff.
As for "How""how", there just isn't any info. WKThe Witch-king holds a flaming sword, stares at Gandalf, and the staff explodes.