Contrary to popular belief, there is nothing in Data's programing that would prevent him from doing "bad" things like lying or killing. He has free will just as much as any other Starfleet officer.
Data is much more human than you might guess at first. He is more akin to a human on the autism spectrum than a robot with hard-coded programming.
Just happened to me yesterday. I needed a 12v power adapter to trigger cable, but I had thrown out the previous one thinking I would never use it.