Aligning a single triangle object's local origin (y axis) to the triangle's normal (non-backface side)
First off, you are way over complicating this. There is no need to use a script to correct the origin's rotation at all.

Starting with the tree with the array and curve modifier before it is applied (GCF green in images), instead of separating each tree along the curve, create a second tree (X-27 blue in images) and parent it to the tree with the modifiers.



Then set the the first tree's Duplication to Faces to add new trees with the location and rotation of each of the existing trees along the curve. 



Then Make Duplicates Real by pressing Ctrl+Shift+A to make the second set of trees separate objects. Now all of the new trees have there own origins in the correct places.



If you want to, you can delete the curve and the first tree. Also, any tree you now select will also have the correct local rotation.