How to export the results from ego to a text file?

The ego command returns the neighbors of a focal node. Assume that I have a network of 100 nodes, then ego returns a list of 100 lists, with each nested list consisting of neighbors for the focal node. Since different nodes have different number of neighbors, I am unable to use data frame because data frame requires the length of elements to be the same. Then how can I export this list of lists to a text file, along with the name for each focal node?
I would like the output format to look like this:
A B C D …
Z F G H J…
The first node A (Z) is the focal node that I want to have neighbors for. The remaining nodes (B, C, D,…) are the neighbors for A, and F, G, H, J are the neighbors for Z.
Any help will be appreciated!

I’m glad to bump this question if there are new insights in 2024 and 2025.

This should do the trick:

library(igraph)
g <- sample_gnp(100,0.1,directed = FALSE)
V(g)$name <- paste0("V",1:100)
ego_list <- ego(g)
ego_txt <- sapply(ego_list, function(x) paste(V(g)$name[x], collapse = " "))
head(ego_txt)
#> [1] "V1 V5 V19 V22 V50 V52 V62 V72 V75 V78 V82 V93 V96"     
#> [2] "V2 V18 V22 V26 V33 V37 V38 V39 V41 V45 V69 V72 V85 V98"
#> [3] "V3 V18 V25 V50 V51 V56 V57 V62 V65 V79 V81"            
#> [4] "V4 V16 V26 V32 V33 V46 V47 V67 V71 V72 V83 V85"        
#> [5] "V5 V1 V6 V18 V20 V28 V30 V34 V54 V60 V68 V96"          
#> [6] "V6 V5 V11 V30 V44 V52 V59 V61 V63 V77 V80 V93 V97"
#writeLines(ego_txt,"egos.txt")