Hi Eva,
What you don't tell us here is what $var1 and $var2 are for you. My first thought was maybe these variables are assigned text with a return character on the end, which is a common mistake when reading the $var1 or $var2 from user input or a from a file.
Try "chomp"ing the file like this below. That will remove any return characters from the end of the variables, only if the exist.
I had no problems getting it onto one line in the output file from the code you gave us. As you can see I haven't amended your code.
Dean
#!perl
$var1 = "Dean\n";
chomp $var1;
$var2 = "Eva\n";
chomp $var2;
open (file, ">>myfile.txt");
print file "$var1==$var2\n";
close (file);