in reply to Expanding a variable

You're using a single quoted string. Those don't interpolate. Adding double quotes inside makes literal double quotes.

You should either convert the whole string to using double quotes (or equivalent) and escape your backslashes... or put the variable outside the quotes and concatenate it

PS: any reason why you're not using a three arg open and lexical filehandles? Its a good habit to get into.