I spent quite a while looking at your macro, and I'm sorry to say that I don't have a good enough picture of your workflow to help very much.
You can try posting a more complete explanation of your task if you like.
But – the place to start is over again and from the top.
Disable every action.
Get the first action working correctly and move down action by action.
When you're putting together text in variables you can look in the variables panel of Keyboard Maestro's preferences.
And/Or – you can use a Display Text action with the in-window option to properly visualize it.
Example – your write-file action didn't have a complete path. I believe it ended with a .
You should have a full featured text editor like BBEdit for testing regular expressions.
(BBEdit is commercial, but it reverts to lite mode after a 30 day demo period. Even in lite mode it is significantly more powerful than the freeware TextWrangler used to be. It continues to be fully AppleScriptable and its regular expression support is unhampered.)
Note – Keyboard Maestro actions in macros can be renamed to clarify what they are doing.