Animate a Bezier curve deforming a mesh, without the mesh awkwardly rotating
It is doable as scripting, probably using to_track_quat way. 

but an easier way is to use Animation Nodes ad on.
That is a visual / nodal scripting tool really.

There you have a set of spline tools to deal with bezier from creating  to extracting data in any way. More than usual Blender tools.

Specifically for this orient/twist situations, there is a Direction to rotation Node that turns 2 vectors into rotation. Unlike the Blender "Z up" to track quat , it provides a second "guide" direction that can be related to anything. 
(I redesigned that node precisely for these problems)

In the example file, one orientation (Z) is the tangents, the other (Y) is controlled by the empty in the back. 

-

Here's a file with a possible setup do do what you need.
spline deform AN

You need Animation Nodes to make it work. 



A very basic setup, cause you can further combine or animate those too. Or, for example may deform only the points closer to spline, not the far away (as xy here) or vary the second rotation along the spline etc.