Dryer vent passing through two wooden beams. Is it safe?
Yes, that's considered safe.  The operating temperature of a dryer vent is not a problem for direct wood contact.  Keep the vent clear and you'll have no fire.

Ensure all joints are foil taped, so lint does not escape from the pipe.  Should lint escape the pipe, it can build up in the wall.

Use a "long sweep" elbow to make the vent easier to clean out.  Modern code in some states requires posting the effective pipe length at the dryer end (and it's a good idea regardless).  Dryers have specific length maximums mentioned in their user manuals.

Depending on your climate, a high quality vent hood can save energy by reducing both drafts coming in, and reduce back-pressure on the dryer going out.