I would have thought that the return value of a successful chomp would be interpreted as "true", but it appears that it returns false.
According to the documentation for
chomp:
It returns the total number of characters removed from all its arguments.
If there is no newline, for example, it returns 0; if there
is a newline, it returns 1.
So, chomp $_ will return 1, which is true, which causes the ternary operator to return the 'true' result. In your non-working case, it returns the empty string. In your working case, it returns the $_ without the newline.