I believe that you are right and the reason is that the Raycast will hit any object in the same collision layer as it, be it a player or a tilemap or any other object you add in the future.
Based on that, I believe you have 2 possible solutions:
1) If the tilemap should never block the "vision" of the enemy, you can change everything that should be detected by the raycast and the raycast itself to a different collision layer.
2) Add a check by the kind of object or in which group the object is when the collision happens and ignore everything that is not the player, in this case you can block the vision of the enemy with different objects.
Bonus option, 1 or 2 should solve most of your cases, but if you have some very specific case that you cannot make it work with either, you can cast the Ray towards where it should using the Space and whenever you hit something that should be bypassed you add it to the ignore list (3rd parameter of the intersect_ray method) and cast it again. I would avoid this method if possible due to the possibility of casting too many rays in a single physics loop, but the possibility exists.
I would look into the Ray-casting Space anyway if you need something more complex.