Yes, you can certainly use with. However, if it will not mean the same thing as it would if you used by.
The two different senses can be paraphrased.
doing the right thing by:
"I don’t know how long I stood there weighing the pros against the cons—doing what's right for Jacob [giving him the money I found], seeing my closest friend again, being a good person, versus making Edward furious with me."
doing the right thing with:
"I don’t know how long I stood there weighing the pros against the cons — Jacob and I doing the right thing [giving the money we both found to the police], seeing my closest friend again, being a good person, versus making Edward furious with me."
Both are grammatical, but the meaning changes. By means that the thing that's right benefits the person; with means that the right thing is by both you and the other person together.
Not only are both interpretations grammatical, but they also both make sense and are understandable in this sentence.
I wouldn't change the word on a whim, especially if the use of by was intentional, because they are not interchangeable, but if composing a sentence either could be used, depending on the particular meaning you want to convey.