### Godot version

v4.2.dev.custom_build [0ca854232]

### System information

Pop Os 22.04 lts 12th Gen Intel® Core™ i7-12700H × 20 NVIDIA RTX A2000 8GB 32.0GB  ram

### Issue description

A node that has a script attached to it and it has a couple of child nodes (type of a child node doesn't matter). In the script you have an export variable of type Node. You save the scene into a file and you add it in level scene. When you start to duplicate that scene in the level and you'll hover over exported variable to show a node path, it will show an incorrect path. 


https://github.com/godotengine/godot/assets/33091666/75088d1b-c014-41e0-bae3-46610eccbad1



### Steps to reproduce

1. create a scene with a node and a child node.
2. attach a script to the parent node and create an export variable of type Node
3. assign child node to that exported variable through the editor
4. save the scene and create a level scene where you are going to add just saved scene.
5. _Possibly requires a reboot of the engine before seeing the bug_
6. start duplicating nodes in the level scene

### Minimal reproduction project

[NodeTest.zip](https://github.com/godotengine/godot/files/12781547/NodeTest.zip)

bool is_detected = false;
		while (n != common_parent) {
			if (n->is_unique_name_in_owner() && n->get_owner() == get_owner()) {
				path.push_back(UNIQUE_NODE_PREFIX + String(n->get_name()));
				is_detected = true;
				break;
			}
			path.push_back(n->get_name());
			n = n->data.parent;
		}
		if (!is_detected) {
			n = this;
			String detected_name;
			int up_count = 0;
			while (n != common_parent) {
				if (n->is_unique_name_in_owner() && n->get_owner() == get_owner()) {
					detected_name = n->get_name();
					up_count = 0;
				}
				up_count++;
				n = n->data.parent;
			}
			for (int i = 0; i < up_count; i++) {
				path.push_back(up);
			}
			if (!detected_name.is_empty()) {
				path.push_back(UNIQUE_NODE_PREFIX + detected_name);
			}
		}
	} else {