The saved scene is never removed from the tree, so it can't be added again, that's why
current_scene.queue_free() fails because
queue_free() can only be called on a node in the tree, while
current_scene is removed in the line right before.
Here's a version that should work as an AutoLoad node:
func switch_scene( temp_scene ):
# save scene and remove it from the tree
saved_scene = get_tree().get_current_scene()
get_tree().get_root().remove_child( saved_scene )
# instance and add temporary scene as current scene
var new_scene = load(temp_scene).instance()
get_tree().get_root().add_child( new_scene )
get_tree().set_current_scene( new_scene )
if saved_scene != null:
# free temporary scene
# add saved scene back to the tree
saved_scene = null
For this example, I renamed
switch_scene() and pass the name of the scene file to temporarily switch to.
Also, keep in mind that
_ready() are called on all the restored scene's nodes when the scene is reinserted.