Is this a potentially dangerous situation?
Yes. The question is how great the potential for danger actually is, and I suspect it is quite small.
The Schengen codes say nothing to cause concern with your plan. They simply say that periods of stay authorized under a long-stay visa are not considered for the 90/180-day calculation relevant to short-stay visas.
But national laws are also relevant. If the Portuguese authorities are of the opinion that you must have an entry stamp on your D visa before your presence in Portugal can be considered "authorized" by that visa, there could be trouble.
The more general concern expressed in your question, that you might appear to have overstayed, is not particularly worrisome. If anyone ever looks at your movements in and out of the area, you can use both passports to establish when you entered and left. There's no requirement that an exit stamp be in the same passport as the entry stamp. In fact, if you leave after being in the Schengen area for over 90 days, you may need to show both passports, since one has the entry stamp and the other has your visa.
To avoid the problem, you can travel out of the Schengen area after you get the passport with the visa, but before you have been there for 90 days. When you leave, show the passport with the entry stamp, and when you return, show the passport with the visa.