Loop at intersection of two objects (script)
Bmesh bisect plane.

Here is a script that bisects one mesh with a plane and creates a new  mesh object with the intersecting edges.



In test example


Grid is a 100 x 100 grid displaced with a cloud texture via a
modifier (not applied).
Plane is a single face default plane, named "Plane".
Move plane to desired location and run script.
New object "Bisect" has the edges of the bisection only.



Still of result, since I hit stop on gif to quickly

2.8 version

import bpy
import bmesh

context = bpy.context
dg = context.evaluated_depsgraph_get()
scene = context.scene 
ob = context.object
plane = scene.objects.get("Plane")

if plane and ob:
    pmw = plane.matrix_world
    face = plane.data.polygons[0]
    plane_co = pmw @ face.center
    plane_no = pmw @ (face.center + face.normal) - plane_co 
    bm = bmesh.new()
    bm.from_object(ob, dg)
    bmesh.ops.transform(bm,
            verts=bm.verts,
            matrix=ob.matrix_world)

    x = bmesh.ops.bisect_plane(bm,
            geom=bm.faces[:] + bm.edges[:] + bm.verts[:],
            clear_inner=True,
            clear_outer=True,
            plane_co=plane_co,
            plane_no=plane_no,
            )
    # new object
    me = bpy.data.meshes.new("Bisect")
    bm.to_mesh(me)
    ob = bpy.data.objects.new("Bisect", me)
    context.collection.objects.link(ob)


2.7x version


Result of running in 2.79 on modified grid, using a one face plane object named "Plane"

import bpy
import bmesh

context = bpy.context

scene = context.scene 
ob = context.object
plane = scene.objects.get("Plane")

if plane and ob:
    pmw = plane.matrix_world
    plane_co = pmw.translation
    face = plane.data.polygons[0]
    plane_no = pmw * (face.center + face.normal) - pmw * face.center 
    bm = bmesh.new()
    bm.from_object(ob, scene)
    bmesh.ops.transform(bm, verts=bm.verts, matrix=ob.matrix_world)
    x = bmesh.ops.bisect_plane(bm,
            geom=bm.faces[:] + bm.edges[:] + bm.verts[:],
            clear_inner=True,
            clear_outer=True,
            plane_co=plane_co,
            plane_no=plane_no,
            )
    # new object
    me = bpy.data.meshes.new("Bisect")
    bm.to_mesh(me)
    ob = bpy.data.objects.new("Bisect", me)
    scene.objects.link(ob)