import sys

# get hits from miranda scans
cap = ""
with open (sys.argv[1]) as infile1:
    for line1 in infile1:
        line1 = line1.strip()
        if "%" in line1 and "Forward:" not in line1:
            #print(line1)
            cap = cap + line1 + "\n"
allregnettf = open(sys.argv[2], "w")
allregnettf.write(cap)
allregnettf.close()

@@ -39,17 +39,8 @@
 ans%0A
-cap = %22%22%0A
 with
@@ -44,17 +44,16 @@
 ith open
- 
 (sys.arg
@@ -78,28 +78,46 @@
     
-for line1 in in
+with open(sys.argv%5B2%5D, %22w%22) as out
 file
-1
 :%0A  
@@ -126,38 +126,40 @@
     
+for 
 line1 
-= line1.strip()%0A
+in infile1:%0A  
         
 if %22
@@ -154,16 +154,18 @@
         
+  
 if %22%25%22 i
@@ -217,135 +217,29 @@
     
-#print(line1)%0A            cap = cap + line1 + %22%5Cn%22%0Aallregnettf = open(sys.argv%5B2%5D, %22w%22)%0Aallregnettf.write(cap)%0Aallregnettf.close(
+    outfile.write(line1
 )%0A

Write output on the file.