Save a generated scene not work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NullPointer

Hi I am a beginner on GoDot scripting and had a problem to save a custom generated scene.
Here my GdScript to save a custom generated scene.

extends Node 

func _ready():
	example()
	#generate_level()
	#load_level()
	pass
	
	
func  example():
	var roomTemplates = ResourceLoader.load("res://genarate/room_templates.tscn")
	if roomTemplates == null: # check for errors
        print("cant load room templates")
        return
	
	# get example room from template
	var root = roomTemplates.instance()
	var startRoom = root.get_node("start")
	
	# build new scene node and add room
	var level = Node.new()
	level.set_name("test")
	var parent = startRoom.duplicate()
	level.add_child(parent)
	parent.set_owner(level)
	
	# add children to parent
	# ? why is this necessayr becaus i use duplicate on original node?
	for child in parent.get_children():
		parent.add_child(child)
		child.set_owner(parent)
	print("scene to save")
	level.print_tree()
	
	# save scene
	print("save scene")
	var packed_scene = PackedScene.new()
	var result = packed_scene.pack(level)
	if result == OK:
		print("save doungen")
		print(ResourceSaver.save("res://test.tscn", packed_scene))
	
	print("load scene")
	var scene = ResourceLoader.load("res://test.tscn")
	if scene == null: # check for errors
        print("cant load scene")
        return
	print("scene loading success")
	scene.instance().print_tree()

The script works so far but the scene is not fully saved.
Here the sysout

scene to save
.
start
start/CollisionShape
start/floor
start/ceiling
start/wall
start/wall2
start/wall3
start/wall4
start/wall5
start/wall6
start/door
save scene
save doungen
0
load scene
scene loading success
.
start

The saved scene contains only the “start” node without any childs.
But when I save the parent node instead all childs are saved.

What I doing wrong?