The task of generating a temporary file and renaming it is greatly simplified by Perl's "-i" option, along with the "-p" option. The "-i" option edits a file in place, and makes a backup with an extension that you specify, such as ".bak". The "-p" option puts a read and print loop around your code. These can be combined with unix "find" command and the "xargs" command to make a nice one-liner for the command line in unix that does it all. Here is one to add a line to all files with the file extentsion ".fileext".
find . -name '*.fileext' -print0 | xargs -0 perl -pi'.bak' -e 'print "
+#something3.cfg\n" unless $c++;'
If you're on windows, you can build a .bat to do the xargs work. Use an editor to make a file that contains
perl inplace.pl firstFile.fileext
perl inplace.pl secondFile.fileext
...
Where the inplace.pl file contains
#!perl -pi'*'
print "#something3.cfg\n" unless $cnt++;