part of code appended into string, resulting in very strange serial output

That's not a program. Please read How to Use the Forum.