In the midst of all the generosity described in chapter 4, Ananias and Sapphira decide they want to appear generous without actually being generous. The church is in its infancy, so problems like this threaten to destroy the church even before it gets off to a healthy start. God deals very harshly with Ananias and Sapphira for their lying. Even this causes the church to continue to grow. Deception from within the church and persecution from outside the church are not able to prevent the church from moving forward.
Trying to look like we are godlier than we actually are is a common problem. It’s easier to do the right things when someone is watching and less honorable things when no one is looking. God isn’t impressed by that kind of godliness, and it threatens the unity of Jesus’ church. It would be better to be honest about our failing than to pretend we don’t have any.