Yes, the machine "knows," but it does not change the theoretical return. The machines function and pay the same whether you're using free-play or not. This same question is also asked in connection with slot club cards. Many believe that machines are programmed to pay differently when they detect that a slot card is being used, but that also is not true.
Of course, even though the return percentages don't change, there's a very big difference in your expected result when using free-play. For example, if you play $20 through once on a 9/6 Jacks or Better machine, assuming you know how to play the optimal strategy -- which you can do nearly perfectly if you study with training programs and use strategy cards -- your result will be 20 x -.0046 (the difference between 100% and the 99.54% return for this schedule) = -.092. That's a loss of about 9¢, leaving $19.91 from your twenty-dollar bill. If you play though $20 in free-play, you still lose that 9¢, but keep the $19.91 remaining from the money the casino has given you to play.
Update: It was brought up that the return on free-play can be less than the return on cash play when slot club points are not awarded for the former. This is true (and demonstrates the point that the machine really does "know"); however, the base return remains unaffected, as explained.