in reply to file duplication error

All your code does is that it appends a line to the end of the file. This can far easier be written as:
open(fileOUT,">>../Rules1.txt") or dienice("Can't open counter.txt: $! +");; print fileOUT "Code1\n"; close(fileOUT);

holli, regexed monk