Why do I get this error? Loading large text file to Blender
Some of the way there

Here is some changes to get you some of the way there.  Unfortunately I have a late version of 2.79 where the boolean modifier no longer has the solver property, so I can't be sure of result.


add and remove the cylinder once at start and end respectively.
set the cd object as active and select.
reference the modifier when added, apply by reference (name).


Edited script:

import bpy
context = bpy.context
scene = context.scene
bpy.ops.mesh.primitive_cylinder_add(
    vertices = 3000, 
    radius = 0.5, 
    depth = 10,
    location = (0, 0, 0)
        )
cylinder = context.object
cylinder.select = False
cd = scene.objects['ISO 10791 M1 blank cd 0.0025']
scene.objects.active = cd
cd.select = True
with open(bpy.path.abspath("//cutting position trial.txt")) as content:            
    for i, line in enumerate(content):
        print(i)

        # extract tool position
        x, y, z = [float(n) for n in line.split(' ',2)]
        cylinder.location = (x, y, z + 5)
        scene.update() # may not be needed.
        # add BOOLEAN modifier
        m = cd.modifiers.new('Boolean', 'BOOLEAN')
        m.operation = 'DIFFERENCE'
        m.object = cylinder
        #m.solver = 'CARVE'

        # apply modifier
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier=m.name)
bpy.data.objects.remove(cylinder)