As for "why" he decides to be "Jack in the country" and "Earnest in the city" from his friend Algernon whom also happens to be "Algy in the city who Bunbury's in the country" is nothing but the author's own personal contempt to the hypocrisy of Victorian society and their plentiful double-lives. In the story, as it is, it comes as a surprise in a way to the reader to realize that, after their extended friendship, Algernon knew nothing of "Jack" and Earnest knew nothing of Bunbury, which leads us to realize that the two had a quite shallow relationship, much like those of Victorian, upper class Londoners at that time.
Jack keeps two different personae, Jack and Ernest. He is Jack in the country and Ernest in the city. Jack is very responsible, the care-taker of a young lady, and very wealthy. Ernest is carefree, frivolous, and impetuous. Jack doesn't want Algernon to know about his double life, otherwise it might lose its appeal. Wilde is using this to create a sense of irony and satire, mocking the dutiful attitude of Victorian society.