Your current issue is that the as soon as Surface.ByUnion detects a disjointed surface it returns all surfaces integrated into a single polysurface, rather than merging adjacent/overlapping surfaces into a series of surfaces, and then building a polysurface from the result.
This Python should make short work of that:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
surfs = IN[0] #the surfaces to union from the Dynamo environment
mergedSurfaces = [] #the resulting groups of surfaces
while surfs: #while there are items in the surfs list
srf = surfs.pop(0) #take the first surface out of the list
found = False #set found to false
tested = [] #an empty list for tested surfaces
toTest = [i for i in surfs] #set toTest to each item in the surfs list
while toTest: #while there are items in the toTest list
test = toTest.pop(0) #take the first item out of the toTest list
if test.DoesIntersect(srf): #if the test item intersects the srf
surfs.remove(test) #remove the test item from the surfs list
srf = Surface.ByUnion([srf,test]) #set the srf to the union of the the test item and the srf
found = True #set found to true
else: #if not intersecting
pass
if not found: mergedSurfaces.append(srf) #if found was not set to true, append the srf object to the merged surfaces list
else: surfs.append(srf) #otherwise append the srf object to the surfs list
OUT = mergedSurfaces #return the merged surfaces
From there you can proceed with building the polysurface, and extracting the outside edges. However it looks as if your can leverage Surface.PerimeterCurves and convert to a PolyCurve directly by way of the PolyCurve.ByGroupedCurves node.
Looks something like this:
From there you should have the Dynamo equivalent of the “shrinkwrap” done, and you can move onto the integration as desired (perhaps by generating the linework in the model as polylines; or by skipping that step and moving into the second and third graph). I leave that work to you though - you’re pretty close from what I see!