Since you're not changing directories, I assume that your file is in the user's home directory - or $filename contains an explicit path to the file with valid seperators etc.
I also echo the sentiment that telnet is the wrong tool for this job... just grab the file with Net::FTP and operate on it locally.