This gives a small, but not relevant, performance improvement when calling importmulti RPC since MarkDirty is called only once.
Note that ImportScript is not atomic: https://github.com/bitcoin/bitcoin/blob/920c090f63f4990bf0f3b3d1a6d3d8a8bcd14ba0/src/wallet/rpcdump.cpp#L227-L242
ie something can fail after a successful AddWatchOnly, which could lead to invalid cached balances. That’s why the MarkDirty call is done as early as possible.