The problem is because of HEREDOC usage. Instead you could quote the whole code as
#!/bin/bash/usr/bin/expect -c 'spawn ssh dinesh@myhostset prompt ":|#|\\\$"expect "password"interact'