Script to change Computername/hostname causing bizarre Terminal behavior
In the comments, @MorganR wondered if the code that reads from the CSV file was including a strange character within $compName.

One way to test for odd, perhaps non-printable characters is to use od.  It has an obscure name (stands for "octal dump"), but it is useful.  It shows the detail of each character in an input stream.

I usually start by using -c argument, which causes od to output each character detail as "C-style escaped characters"... there are other arguments to output as hex, octal (still occasionally useful!), etc.

For example (notice the normally invisible \n is shown):

$ echo "foo" | od -c
0000000    f   o   o  \n                                                
0000004


So, if that makes sense, my suggestion is: try adding the line echo $compName | od -c to the script after the "loop through the CSV" section.

In the comments, the issue has turned out to be an unexpected \r character.  I think the likely cause for this is that the CSV file has CRLF (=\r\n) line endings (was it created on a Windows system perhaps?), but the read ser loc command in the script is expecting just LF (=\n).