In both cases, Rohan is more of an immediate threat to his goals than Gandalf is. However, the specifics differ slightly between the two versions.
In the book
In the novel, the arrival of Rohan coincides with the breakup of a supernatural darkness, meant to ease the battle for Sauron's sunlight-sensitive soldiers1. The combination of a large number of reinforcements and the diminished effectiveness of his own army means that the With-king's attention is urgently needed elsewhere (emphasis mine):
The darkness was breaking too soon, before the date that his Master had set for it: fortune had betrayed him for the moment, and the world had turned against him; victory was slipping from his grasp even as he stretched out his hand to seize it. But his arm was long. He was still in command, wielding great powers. King, Ringwraith, Lord of the Nazgûl, he had many weapons. He left the Gate and vanished.
Return of the King Book V Chapter 6: "The Battle of the Pelennor Fields"
Ultimately, the Witch-king is more concerned with taking the city than with destroying Gandalf specifically.
In the films
As with many things in the films, this isn't given an in-universe explanation. However, bear in mind that:
- From the Witch-king's perspective, Gandalf is no threat at all. He's just demonstrated that he has no difficulty ruining Gandalf's day, so there's no pressing need to kill the wizard. He can always just come back and do it later
- He lacks information. Consider what information the Witch-king has: he knows he has a vulnerable Wizard in front of him, and he knows that somebody hostile has just arrived. It makes the most tactical sense to assess who the new arrivals are, because they're the more immediate threat to his ultimate goal of taking the city; although Gandalf is (as far as he knows) the largest threat to him directly, a single Wizard can't destroy an entire Orcish army
The Rohirrim have a pretty good tactical position. It doesn't matter whether or not the Witch-king knows who just arrived; he knows that there are hostiles to the north, while most of his army is in an enclosed environment, fenced in by Mount Mindolluin to the west, the River Anduin to the south, and retreat (which seems an unlikely tactic) to the east. The orcs are boxed in, and the Witch-king knows it.
All of which is a roundabout way of saying that his particular set of skills is more urgently needed on the field, rather than trading barbs with some has-been wizard.