Update. The problem is that you're using the -k switch with filter to write to the input file, which isn't permitted.

Run this alias and the red echo shows there is only 1 line. However remove either of the semi-colons, and the red echo now shows 3 lines. That means my debug command which includes the command to show the number of lines in the file could alter the effect of a script because it flushes the cache to disk.

//.remove test.ini | writeini test.ini section item value | writeini test.ini section item2 value2 | ;flushini test.ini | ;echo 3 -a $lines(test.ini) | write -l3 test.ini foo | echo 4 -a $lines(test.ini)

now insert this alias into a remote script:

alias foofilter {
if (!%inc_i) set -u99 %inc_i 2
flushini test.ini
echo -a $1-
write -l $+ %inc_i test.ini value $+ %inc_i $+ = $+ %inc_i
inc %inc_i

and then run the command:

/filter -k test.ini foofilter

and your error message will display. Inserting a "flushini test.ini" won't hold the error at bay either. Instead, your -k alias needs to examine the $1 to decide whether to /return $1 unchanged, or to return altered contents.