I haven't had the chance to dig into this further, but just wanted to log this somewhere to prevent forgetting about it.
Assigning a value to $line in wp shell gives very unexpected results, causing some pretty confusing behavior and bugs.
Behavior:
wp shell
wp> $line = 'this wont work';
=> string(14) 'this wont work'
wp> $line;
=> string(13) "return $line;"
wp> $linetest = 'this will';
=> string(9) "this will"
wp> $linetest;
=> string(9) "this will"