Mainly because of amendments and attachments. For example a bill will be introduced, say that would state all clothing must be flame retardant, just as example. Why wouldn't somebody vote for it? Because another Congress person will attach an amendment that would require states to accept off or on shore drilling, or maybe ban it. Either way, the bill that was a good bill originally, is defeated because of amendments attached. More often than not there is a lot of pork ( money given to states, cities, local area for local projects) included. If it was passed, the purpose of the bill if signed by the President would become law. However all those attachments would also become law in their own right.
Another reasons is if one congress person opposes a bill, he/she will "deal" with other congress people who don't care about this bill, to vote against it, and in return he/she will support or oppose another bill the other congress person supports or opposes.
Then you have bill like the McCain-Kennedy immigration reform bill, the original bailout bill the House voted down, because constituents called Congress demanded they vote it down.
Lobbyists can play a huge role. In fact, that's what they are there for. To influence Congress to vote down legislation that would not benefit their cause or those they represent.