You can read the file within your expect script.
Open the file and assign the file descriptor to a variable, read each line and execute the above code you wrote.
set fildes [open "myhosts.txt" r]
set ip [gets $fildes]
while {[string length $ip] > 0} {
spawn telnet $ip
expect "User Name :"
send "username\r"
expect "Password :"
send "password\r"
expect ">"
send "4\r"
expect "*#"
exit
set ip [gets $fildes]
}
close $fildes